package com.bs.blogspace.controller;


import com.bs.blogspace.anno.Log;
import com.bs.blogspace.model.Result;
import com.bs.blogspace.pojo.SpaceArticle;
import com.bs.blogspace.service.SpaceArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@Slf4j
public class SpaceArticleController {
    @Autowired
    private SpaceArticleService spaceArticleService;


    @PostMapping("/writeEssay")
    @ResponseBody
    public Result writeEssay(@RequestBody SpaceArticle spaceArticle){
        log.info("发表文章,{}",spaceArticle);
       return spaceArticleService.addArticle(spaceArticle);
    }

    @Log
    @GetMapping("/deleteEssay")
    @ResponseBody
    public Result DeleteEssay(@RequestParam("essayId") String essayId){
        log.info("删除文章,{}",essayId);
        return spaceArticleService.deleteArticle(essayId);
    }

    @GetMapping("/getEssay")
    @ResponseBody
    public Result getEssay(@RequestParam("spaceId")String spaceId){
        log.info("获取空间内文章；{}",spaceId);
        return spaceArticleService.getEssay(spaceId);

    }
}
